package jjwt.study.Config;

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.token.TokenEnhancer;

import java.util.HashMap;
import java.util.Map;

/**
 * 描述: Jwt内容增强器
 * @author Ychiha
 * @version 1.0
 * @date 15/1/2022 上午12:12
 */

public class JwtTokenEnhancer implements TokenEnhancer {

    //效果就是添加信息到jwt中
    @Override
    public OAuth2AccessToken enhance(OAuth2AccessToken auth2AccessToken, OAuth2Authentication authentication) {
        Map<String, Object> info = new HashMap<>();
        info.put("enhance", "enhance info");
        ((DefaultOAuth2AccessToken)auth2AccessToken).setAdditionalInformation(info);
        return auth2AccessToken;
    }

}
